/*
 * This file should be edited as appropriate.
 */
package database;


public class DataBase {
	BufferManager bufferManager;

    public DataBase() {}

    public DataBase(String dbName, int bufferSize) {
    	bufferManager = new BufferManager(bufferSize*1000,dbName);
    }

    public Table openTable(String tableName) {
    	Table t=new Table(tableName);
    	bufferManager.storageManager.getPageOfTable(t,0);
    	return t;
    }
    

    public void openDataBase(String dbName, int bufferSize) {
    	DataBase db = new DataBase(dbName, bufferSize);
    	this.bufferManager = db.bufferManager;
    }
    
    public Table createTable(String tableName, Object[][] tableSchema) {	
    	Table t= new Table(tableName,tableSchema);
    	t.bufferManager = this.bufferManager;
    	bufferManager.saveSchema(t,tableSchema);
    	return t;
    }
    
    public void close() {
		int i;
		for(i=0 ; i < bufferManager.pool.numberPages ; i++){
			bufferManager.storageManager.store(bufferManager.pool.pages[i]);
		}
	}
}
